import os
import sys
import shutil
import logging

PATH_DEV = os.path.dirname(os.getcwd())
PATH_OPENRESTY = "/usr/local/openresty/nginx"
PATHLIST_STATIC = ["html", "luafile", "conf", "scripts_framework"]
'''
#conf --cert
      |-nginx_release.conf
      |-nginx_dev.conf

'''


def chk_installpath():
    if not os.path.isdir(PATH_OPENRESTY):
        logging.error("Not find openresty install!")
        sys.exit()


def update_loadl():
    for fname in os.listdir(PATH_DEV):
        if fname in PATHLIST_STATIC:
            fobj = os.path.join(PATH_DEV, fname)
            if os.path.isdir(fobj):
                tarobj = os.path.join(PATH_OPENRESTY, fname)
                if os.path.isdir(tarobj):
                    shutil.rmtree(tarobj)
                shutil.copytree(fobj, tarobj)


if __name__ == "__main__":
    chk_installpath()
    update_loadl()
